package com.ruoyi.web.controller.qiushi.followup;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.qiushi.domain.followup.QiushiForm;
import com.ruoyi.qiushi.service.followup.IQiushiFormService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问答单Controller
 *
 * @author ruoyi
 * @date 2023-12-19
 */
@RestController
@RequestMapping("qiushi/followup/qiushiform")
public class QiushiFormController extends BaseController {
    @Autowired
    private IQiushiFormService qiushiFormService;

    /**
     * 查询问答单列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:followup:qiushiform:list')")
    @GetMapping("/list")
    public TableDataInfo list(QiushiForm qiushiForm) {
        startPage();
        List<QiushiForm> list = qiushiFormService.selectQiushiFormList(qiushiForm);
        return getDataTable(list);
    }

    /**
     * 导出问答单列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:followup:qiushiform:export')")
    @Log(title = "问答单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QiushiForm qiushiForm) {
        List<QiushiForm> list = qiushiFormService.selectQiushiFormList(qiushiForm);
        ExcelUtil<QiushiForm> util = new ExcelUtil<QiushiForm>(QiushiForm.class);
        util.exportExcel(response, list, "问答单数据");
    }

    /**
     * 获取问答单详细信息
     */
    @PreAuthorize("@ss.hasPermi('qiushi:followup:qiushiform:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(qiushiFormService.selectQiushiFormById(id));
    }

    /**
     * 新增问答单
     */
    @PreAuthorize("@ss.hasPermi('qiushi:followup:qiushiform:add')")
    @Log(title = "问答单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QiushiForm qiushiForm) {
        qiushiForm.setCreateTime(new Date());
        qiushiForm.setUpdateTime(new Date());
        return toAjax(qiushiFormService.insertQiushiForm(qiushiForm));
    }

    /**
     * 修改问答单
     */
    @PreAuthorize("@ss.hasPermi('qiushi:followup:qiushiform:edit')")
    @Log(title = "问答单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QiushiForm qiushiForm) {
        qiushiForm.setUpdateTime(new Date());
        return toAjax(qiushiFormService.updateQiushiForm(qiushiForm));
    }

    /**
     * 删除问答单
     */
    @PreAuthorize("@ss.hasPermi('qiushi:followup:qiushiform:remove')")
    @Log(title = "问答单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(qiushiFormService.deleteQiushiFormById(id));
    }
}
